package fenetre;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JButton;

import metier.CL_artiste;

public class CL_ajt_aut extends JFrame implements MouseListener , ActionListener{
	private JTextField nom;
	private JTextField prenom;
	private CL_artiste o_artiste;
	public CL_ajt_aut() {
		
		JLabel lblAjouterUnAuteur = new JLabel("Ajouter un auteur");
		
		JLabel lblNom = new JLabel("Nom");
		
		JLabel lblPrnom = new JLabel("Pr\u00E9nom");
		
		nom = new JTextField();
		nom.setColumns(10);
		
		prenom = new JTextField();
		prenom.setColumns(10);
		
		o_artiste = new CL_artiste();

		
		JButton btnAjouter = new JButton("Ajouter");
		btnAjouter.addActionListener(this);
		btnAjouter.addActionListener(new ActionListener() 
		{ 
				public void actionPerformed(ActionEvent e) { }	
		});
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(btnAjouter)
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
							.addComponent(lblAjouterUnAuteur)
							.addGroup(groupLayout.createSequentialGroup()
								.addComponent(lblNom)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(nom))
							.addGroup(groupLayout.createSequentialGroup()
								.addComponent(lblPrnom)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(prenom, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addContainerGap(255, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblAjouterUnAuteur)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNom)
						.addComponent(nom, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblPrnom)
						.addComponent(prenom, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnAjouter)
					.addContainerGap(26, Short.MAX_VALUE))
		);
		getContentPane().setLayout(groupLayout);
	}{

}

@Override
public void actionPerformed(ActionEvent e) {
	// TODO Auto-generated method stub
	
		String nomBouton = e.getActionCommand();

		if (nomBouton == "Ajouter")
		{
			String nom = this.nom.getText();
			String prenom = this.prenom.getText();
			int id_artiste = 0; 
			id_artiste = this.o_artiste.m_Ajouter_Artiste(nom,prenom);
			if(id_artiste != 0)
			{
					dispose();
			}
			
		}
	
}

@Override
public void mouseClicked(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}

@Override
public void mouseEntered(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}

@Override
public void mouseExited(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}

@Override
public void mousePressed(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}

@Override
public void mouseReleased(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}
}
